<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>python3 基础语法 | 老李的个人博客</title>
    <meta name="description" content="老李的个人网站，记录着自己的个人成长。">
    <link rel="icon" href="/logo.jpg">
    
    <link rel="preload" href="/assets/css/0.styles.1db6e86b.css" as="style"><link rel="preload" href="/assets/js/app.9a5f4f15.js" as="script"><link rel="preload" href="/assets/js/2.fb839ad7.js" as="script"><link rel="preload" href="/assets/js/8.92fb4af1.js" as="script"><link rel="prefetch" href="/assets/js/10.3edf41db.js"><link rel="prefetch" href="/assets/js/11.7ba525f6.js"><link rel="prefetch" href="/assets/js/12.bf9d74b3.js"><link rel="prefetch" href="/assets/js/13.b1401722.js"><link rel="prefetch" href="/assets/js/14.35ef07af.js"><link rel="prefetch" href="/assets/js/15.ffbfdd10.js"><link rel="prefetch" href="/assets/js/3.ce5bc181.js"><link rel="prefetch" href="/assets/js/4.76416af2.js"><link rel="prefetch" href="/assets/js/5.1b1ec201.js"><link rel="prefetch" href="/assets/js/6.529193cc.js"><link rel="prefetch" href="/assets/js/7.efd2306a.js"><link rel="prefetch" href="/assets/js/9.548be40e.js">
    <link rel="stylesheet" href="/assets/css/0.styles.1db6e86b.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">老李的个人博客</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">算法学习网站</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://leetcode-cn.com/problemset/all/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  力扣
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="https://www.runoob.com" target="_blank" rel="noopener noreferrer" class="nav-link external">
  菜鸟教程
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">Python</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/Django/" class="nav-link">Django</a></li><li class="dropdown-item"><!----> <a href="/blog/HTML/" class="nav-link">HTML</a></li><li class="dropdown-item"><!----> <a href="/blog/Python/" class="nav-link router-link-exact-active router-link-active">Pthon</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">算法学习网站</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://leetcode-cn.com/problemset/all/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  力扣
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></li></ul></div></div><div class="nav-item"><a href="https://www.runoob.com" target="_blank" rel="noopener noreferrer" class="nav-link external">
  菜鸟教程
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title">Python</span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/Django/" class="nav-link">Django</a></li><li class="dropdown-item"><!----> <a href="/blog/HTML/" class="nav-link">HTML</a></li><li class="dropdown-item"><!----> <a href="/blog/Python/" class="nav-link router-link-exact-active router-link-active">Pthon</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>python3 基础语法</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/blog/Python/#python3-基础语法" class="sidebar-link">python3 基础语法</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/blog/Python/#编码" class="sidebar-link">编码</a></li><li class="sidebar-sub-header"><a href="/blog/Python/#注释" class="sidebar-link">注释</a></li><li class="sidebar-sub-header"><a href="/blog/Python/#数据类型" class="sidebar-link">数据类型</a></li><li class="sidebar-sub-header"><a href="/blog/Python/#字符串" class="sidebar-link">字符串</a></li></ul></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h2 id="python3-基础语法"><a href="#python3-基础语法" aria-hidden="true" class="header-anchor">#</a> python3 基础语法</h2> <h3 id="编码"><a href="#编码" aria-hidden="true" class="header-anchor">#</a> 编码</h3> <p>默认情况下，Python 3源码文件以 UTF-8 编码，所有字符串都是 unicode 字符串。 当然你也可以为源码文件指定不同的编码：
<code># -*- coding: cp-1252 -*-</code></p> <p>在Python 3中，非-ASCII 标识符也是允许的了。</p> <h3 id="注释"><a href="#注释" aria-hidden="true" class="header-anchor">#</a> 注释</h3> <p>Python中单行注释以#开头，多行注释用三个单引号（'''）或者三个双引号（&quot;&quot;&quot;）将注释括起来。</p> <h3 id="数据类型"><a href="#数据类型" aria-hidden="true" class="header-anchor">#</a> 数据类型</h3> <p>python中数有四种类型：整数、长整数、浮点数和复数。</p> <p>*整数， 如 1
*长整数 是比较大的整数
*浮点数 如 1.23、3E-2
*复数 如 1 + 2j、 1.1 + 2.2j</p> <h3 id="字符串"><a href="#字符串" aria-hidden="true" class="header-anchor">#</a> 字符串</h3> <p>*python中单引号和双引号使用完全相同。
*使用三引号('''或&quot;&quot;&quot;)可以指定一个多行字符串。
*转义符 ''
*自然字符串， 通过在字符串前加r或R。 如 r&quot;this is a line with \n&quot; *则\n会显示，并不是换行。
*python允许处理unicode字符串，加前缀u或U， 如 u&quot;this is an unicode string&quot;。
*字符串是不可变的。
*按字面意义级联字符串，如&quot;this &quot; &quot;is &quot; &quot;string&quot;会被自动转换为this is string。</p></div> <footer class="page-edit"><!----> <!----></footer> <!----> </main></div><div class="global-ui"></div></div>
    <script src="/assets/js/app.9a5f4f15.js" defer></script><script src="/assets/js/2.fb839ad7.js" defer></script><script src="/assets/js/8.92fb4af1.js" defer></script>
  </body>
</html>
